/* eslint-disable @typescript-eslint/no-explicit-any */
import { DetectorInfo } from '../interface/class';
import { post, customError } from '../index';
import { ReturnType, HomeResponse } from '../interface'
import { URL_CHANNEL, URL_HOME, URL_READ } from '../base/url'

export const home = async (): Promise<ReturnType<HomeResponse | undefined>> => {
    try {
        const result = await post<HomeResponse>(URL_HOME)
        if (result?.data?.detector) {
            result.data.detector = new DetectorInfo(result.data.detector)
        }
        return result
    } catch (error: any) {
        return customError(error)
    }
}

/// Mini App
export const lastChannelInfo = async (): Promise<ReturnType<{ newCount: number; messageId: string; text: string } | undefined>> => {
    try {
        return await post(URL_CHANNEL);
    } catch (error: any) {
        return customError(error)
    }
}

export const readChannelInfo = async (params: { messageId: string }): Promise<ReturnType<undefined>> => {
    try {
        return await post(URL_READ, params);
    } catch (error: any) {
        return customError(error)
    }
}